jQuery.validator.addMethod(
	'usertext1',
	function (value) {
		var userReg = /^[\u4e00-\u9fa5a-z]+$/i
		if (userReg.test(value)) {
			return true
		}
		return false
	},
	'用户名只能由汉字或者英文组成'
)
jQuery.validator.addMethod(
	'usertext2',
	function (value) {
		var userReg = /^[\u4e00-\u9fa5a-z]+$/i
		if (userReg.test(value)) {
			var res = value.replace(/[\u4e00-\u9fa5]/g, 'aa')
			var userFlag = res.length < 14
			return userFlag
		}
	},
	'用户名的长度只能为14个以内'
)
jQuery.validator.addMethod(
	'passwordtext',
	function (value) {
		var passReg =
			/^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?![,\.;:\?]+$)[0-9a-zA-Z,\.;:\?]{8,14}$/
		var passFlag = passReg.test(value)
		return passFlag
	},
	'密码不符合格式要求'
)
jQuery.validator.addMethod(
	'teltext',
	function (value) {
		var telreg = /^1[3-9]\d{9}$/
		var telFlag = telreg.test(value)
		return telFlag
	},
	'电话号码格式不对'
)
$('#bd').validate({
	rules: {
		username: {
			required: true,
			usertext1: true,

			usertext2: true,
		},
		tel: {
			required: true,
			teltext: true,
		},
		password: {
			required: true,
			passwordtext: true,
		},
		password1: {
			required: true,
			equalTo: '#password',
		},
	},

	messages: {
		password1: {
			equalTo: '两次密码不一样',
		},
		tel: {
			required: '电话号码不可为空',
		},
		username: {
			required: '用户名不可为空',
		},
		password: {
			required: '密码不可为空',
		},
	},
	submitHandler: function (bd) {
		//   alert("提交事件!");
		$.ajax({
			url: '/hx/regist.php',
			type: 'get',
			data: {
				user: $('.yhm').val(),
				pass: $('.mima').val(),
				tel: $('.sjh').val(),
			},
			success: function (res) {
				console.log(res)
				alert(res)
				// location.href = './login.html'
			},
			error: function (res) {
				res = JSON.parse(res)
			},
		})
	},
})
